package com;

import com.mapper.WorkerMapper;
import javafx.concurrent.Worker;

public class WorkerTest {
    @Test
    public <SqlSession> void findWorkerByIdTest(){
        Object MyBatisUtils = null;
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        WorkerMapper mapper = sqlSession.getMapper(WorkerMapper.class);
        Worker worker = mapper.selectWorker(1);
        System.out.println(worker.toString());
        sqlSession.close();
    }
    @Test
    public <SqlSession> void insertWorkerTest(){
        Object MyBatisUtils = null;
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Worker worker = new Worker();
        worker.setId(4);
        worker.setName("赵六");
        worker.setAge(36);
        worker.setSex("女");
        worker.setWorkerId(1004);
        WorkerMapper mapper = sqlSession.getMapper(WorkerMapper.class);
        int result = mapper.insertWorker(worker);
        if (result >0){
            System.out.println("成功插入"+result+"条数据");
        }else {
            System.out.println("插入数据失败");
        }
        System.out.println(worker.toString());
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public <SqlSession> void updateWorkerTest(){
        Object MyBatisUtils = null;
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Worker worker = new Worker();
        worker.setId(4);
        worker.setName("李华");
        worker.setAge(28);
        WorkerMapper mapper = sqlSession.getMapper(WorkerMapper.class);
        int result = mapper.updateWorker(worker);
        if (result >0){
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
        System.out.println(worker.toString());
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public <SqlSession> void deleteWorkerTest(){
        Object MyBatisUtils = null;
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        WorkerMapper mapper = sqlSession.getMapper(WorkerMapper.class);
        int result = mapper.deleteWorker(4);
        if (result >0){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public <SqlSession> void selectWorkerByIdAndNameTest(){
        Object MyBatisUtils = null;
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        WorkerMapper mapper = sqlSession.getMapper(WorkerMapper.class);
        Worker worker = mapper.selectWorkerByIdAndName(3,"王五");
        System.out.println(worker.toString());
        sqlSession.close();
    }
}
